<template>
  <div class="dashboard-container">
    <!-- 组织架构 -->
    <div class="dashboard-container">
      <el-card class="tree-card">
        <!-- 用了一个行列布局 -->
        <!-- <tree-tools /> -->
        <!--  -->

        <tree-tools :obj="companyInfo" :isroot="true" @depts="onadd" />
        <el-tree :data="treeData" :props="defaultProps" :default-expand-all="true">
          <!-- <template > -->
          <tree-tools slot-scope="{data}" :obj="data" @depts="onadd" @onedit="onedit" />
          <!-- dialogVisible = true -->
          <!-- </template> -->

        </el-tree>
      </el-card>
    </div>
    <depts ref="depts" v-model="dialogVisible" :node="treenode" @add-success="loaddepartments" />
  </div>
</template>

<script>
// import treeTools from '@/views/departments/components/treeTools'
import treeTools from './components/treeTools.vue'
import { getdepartmentslist } from '@/api/departments'
import { translisttotree } from '@/utils'
// import { depts } from '@/views/departments/components/depts.vue'
import Depts from './components/depts.vue'
export default {
  components: { treeTools, Depts },
  // computed: {
  //   treeTools
  // },

  data() {
    return {
      treeData: [
        // {
        //   name: '张三',
        //   child: [
        //     {
        //       name: '张小三'
        //     },
        //     {
        //       name: '王小三'
        //     }
        //   ]
        // },
        // {
        //   name: '李四',
        //   child: [
        //     {
        //       name: '张小三'
        //     },
        //     {
        //       name: '王小三'
        //     }
        //   ]
        // }
      ],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      companyInfo: {
        name: '传智播客', message: '负责人', id: ''

      },
      dialogVisible: false,
      treenode: {}
    }
  },
  created() {
    this.loaddepartments()
  },
  methods: {
    async  loaddepartments() {
      const res = await getdepartmentslist()
      console.log(res)
      this.treeData = translisttotree(res.depts, '')
    },
    onadd(data) {
      this.dialogVisible = true
      this.treenode = data
    },
    onedit(data) {
      console.log('查看部门 编辑成功')
      // 控制弹窗
      this.dialogVisible = true
      // treenode可以得到值 但不是最新的数据  所以要调接口
      this.treenode = data
      this.$refs.depts.getdeptsinfo(data.id)
    }
  }
}
</script>

<style scoped lang='scss'>

.el-row{
  width: 100%;
}

</style>
